﻿namespace Algoritmia.Problems.Matrix
{
    public static class Matrix
    {
        public static double[][] Product(double[][] a,double[][] b)
        {
            var p = a.Length;
            var q = a[0].Length;
            var r = b[0].Length;
            double[][] result = new double[p][];
            for(int i = 0; i < p; i++)
            {
                result[i] = new double[r];
                for(int j = 0; j < r; j++)
                {
                    for(int k = 0; k < q; k++)
                    {
                        result[i][j] += a[i][k]*b[k][j];
                    }
                }
            }
            return result;
        }

        public static int[][] Product(int[][] a, int[][] b)
        {
            var p = a.Length;
            var q = a[0].Length;
            var r = b[0].Length;
            int[][] result = new int[p][];
            for (int i = 0; i < p; i++)
            {
                result[i] = new int[r];
                for (int j = 0; j < r; j++)
                {
                    for (int k = 0; k < q; k++)
                    {
                        result[i][j] += a[i][k] * b[k][j];
                    }
                }
            }
            return result;
        }
    }
}
